
//校验手机号
function checkPhone() {
    //1.获取手机号的值
    var phone = document.getElementById("phone").value;
    //2.定义正则表达式
    var reg_phone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
    //3.判断值是否符合正则的规则
    var flag = reg_phone.test(phone);
    //4.提示信息
    //  var s_phone = document.getElementById("phone").value;

    if (phone == "") {
        document.getElementById("s_phone").innerHTML = "手机号不能为空";
        //		alert("手机号输入不能为空!");
        //return false;
    }
    else {
        if (flag) {
            //提示绿色对勾
            document.getElementById("s_phone").innerHTML = "";
        } else {
            //提示红色错误信息
            document.getElementById("s_phone").innerHTML = "手机号输入有误";
        }
    }

    // return flag;   
}

//校验密码
function checkPassword() {
    //1.获取密码的值
    var passwordd = document.getElementById("password").value;
    //2.定义正则表达式
    var reg_password = /^\w{6,12}$/;
    //3.判断值是否符合正则的规则
    var flag = reg_password.test(passwordd);
    //4.提示信息
    //    var s_password = document.getElementById("s_password");

    if (passwordd == "") {
        document.getElementById("s_password").innerHTML = "密码不能为空";

        //		return false;
    }
    else {
        if (flag) {
            //提示绿色对勾
            document.getElementById("s_password").innerHTML = "";
        } else {
            //提示红色错误信息
            document.getElementById("s_password").innerHTML = "密码格式有误";
        }
    }

    //    return flag;
}

//校验密码再次输入
function checkRePassword() {
    //1.获取密码的值
    var passwordd = document.getElementById("password").value;
    //2.获取再次输入密码的值
    var repassword = document.getElementById("repassword").value;
    //4.提示信息
    //  var s_repassword = document.getElementById("s_repassword");

    if (repassword == "") {
        document.getElementById("s_repassword").innerHTML = "再次输入密码不能为空";
        return false;
    }
    else {

        if (passwordd == repassword) {
            //提示绿色对勾
            document.getElementById("s_repassword").innerHTML = "";
        } else {
            //提示红色错误信息
            document.getElementById("s_repassword").innerHTML = "两次密码输入不相符";
        }

    }
    //    return flag;
}

//校验用户名
function checkName() {
    //获取用户名的值
    var name = document.getElementById("name").value;

    //定义正则表达式
    var reg_name = /^[\u4e00-\u9fa5a-zA-Z]{2,6}$/;///^[\u4e00-\u9fa5]{2,6}$/;/^[\u4e00-\u9fa5a-zA-Z]{1}$/
    //判断值是否符合正则表达式的规则
    var flag = reg_name.test(name);
    //提示信息
    //   var s_name = document.getElementById("s_name");

    if (flag) {
        //提示绿色对勾
        document.getElementById("s_name").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("s_name").innerHTML = "用户名格式有误";
    }
    //   return flag;
}

//校验性别
function checkSex() {
    //1.获取真实姓名的值
    var sex = document.getElementById("sex").value;
    //2.定义正则表达式
    var reg_sex = /^['男'|'女']$/;
    //3.判断值是否符合正则的规则
    var flag = reg_sex.test(sex);
    //4.提示信息
    //  var s_sex = document.getElementById("s_sex");

    if (flag) {
        //提示绿色对勾
        document.getElementById("s_sex").innerHTML = "";
    } else {
        //提示红色错误信息
        //     document.getElementById("s_sex").innerHTML = "请输入男/女";
    }
    //   return flag;
}

//校验身份证
function checkNumber() {
    //1.获取Email的值
    var number = document.getElementById("number").value;
    //2.定义正则表达式
    var reg_number = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;
    //3.判断值是否符合正则的规则
    var flag = reg_number.test(number);
    //4.提示信息
    //   var s_number = document.getElementById("s_number");

    if (flag) {
        //提示绿色对勾
        document.getElementById("s_number").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("s_number").innerHTML = "身份证格式有误";
    }
    //   return flag;
}

//校验Email
function checkEmail() {
    //1.获取Email的值
    var email = document.getElementById("email").value;
    //2.定义正则表达式
    var reg_email = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    //3.判断值是否符合正则的规则
    var flag = reg_email.test(email);
    //4.提示信息
    //  var s_email = document.getElementById("s_email");

    if (flag) {
        //提示绿色对勾
        document.getElementById("s_email").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("s_email").innerHTML = "Email格式有误";
    }
    //   return flag;
}

	
function register(){
    var unindexed_array = $("#myForm").serializeArray();
    var param = {};
    $.map(unindexed_array, function (n, i) {
        param[n['name']] = n['value'];
    });

    $.ajax({
        type: "post",
        contentType: "application/json",
        url:"http://localhost:8888/user/registered",
        async:false,
        data:JSON.stringify(param),
        dataType:"json",
        success:function(data){
            if(data.code==1){
                    history.go(-1);
            }
        },error:function(data){
            alert("系统错误");
        }
    });
    
}
